package com.yuufa.util;

import java.util.Arrays;

public class Tool {
    
    public static int[] random(int n, int range) {
        
        int[] s = new int[range+1];
        
        for(int i=1;i<=range;i++) {
            s[i] = i;
        }
        
        for(int i=1;i<=range;i++) {
            int r = (int) (Math.random() * range) + 1;
            
            int t = s[i]; s[i] = s[r]; s[r] = t;
        }
        
        return Arrays.copyOfRange(s, 1, n+1);
    }
    
    public static int[] random(int n) {
        
        int[] data = new int[n];
        
        for(int i=0;i<n;i++) {
            int r = (int) (Math.random() * 50) + 1;
            
            data[i] = r;
        }
        
        System.out.print("before:");
        for(int i=0;i<n;i++) {
            System.out.printf("%4d", data[i]);
        }
        System.out.println();
        
        return data;
    }
    
    public static int[] randomHeap(int n) {
        
        int[] data = new int[n + 1];
        
        for(int i=1;i<=n;i++) {
            int r = (int) (Math.random() * 50) + 1;
            
            data[i] = r;
        }
        
        System.out.print("before:");
        for(int i=1;i<=n;i++) {
            System.out.printf("%4d", data[i]);
        }
        System.out.println();
        
        return data;
    }
    
    public static void print(int[] data, int begin, int end) {
        for(int i=begin;i<=end;i++) {
            System.out.printf("%6d", data[i]);
        }
        System.out.println();
    }
    
    public static void output(int[] data, int begin, int end) {
        
        System.out.print("after: ");
        for(int i=begin;i<=end;i++) {
            System.out.printf("%4d", data[i]);
        }
        System.out.println();
    }
}
